package contato.DAO;


import javax.persistence.EntityManager;
import javax.persistence.Query;



import rta.dataacess.Confignot;
import rta.dataacess.Imei;
import rta.dataacess.Usuario;

public class ConfDao extends GenericDAO<Confignot> {

	public ConfDao() {
		super(Confignot.class);

	}

	public ConfDao(EntityManager entityManager) {
		super(Confignot.class, entityManager);
	}

	public Imei findUsuario(Usuario usuario) {
		
		Imei imei = null;
		String hql = "FROM Imei WHERE usuario = ?";

		EntityManager entityManager = getEntityManager();
		Query query = entityManager.createQuery(hql);

		query.setParameter(1, usuario);

		try {
			imei = (Imei) query.getSingleResult();

			return imei;

		} catch (RuntimeException e) {

			return imei = null;

		}
	}

	public Confignot findbyImei(String imei) {
		Confignot conf = null;
		String hql = "FROM Confignot WHERE imei = ?";

		EntityManager entityManager = getEntityManager();
		Query query = entityManager.createQuery(hql);

		query.setParameter(1, imei);

		try {
			conf = (Confignot) query.getSingleResult();

			return conf;

		} catch (RuntimeException e) {

			return conf = null;

		}
	}

}
